﻿using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using UnityEngine;

public class UDPClient {
    private UdpClient udpClient = new UdpClient();
    private IPEndPoint iPEndPoint = null;

    private static UdpClient instance = new UdpClient();
    public static UdpClient Instance { get { return instance; } }

    public void SetEndPoint(string ip, int port)
    {
        iPEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
    }

    public void SendMsg(byte[] buffer)
    {
        udpClient.Send(buffer, buffer.Length);
    }

    public byte[] RecvMsg()
    {
        if (udpClient.Available <= 0) return null;
        byte[] buffer = udpClient.Receive(ref iPEndPoint);
        return buffer;
    }

    public void DisConnect()
    {
    }

    public void Close()
    {
        udpClient.Close();
    }
}
